//
//  OptionOperatorViewController.m
//  MathKids
//
//  Created by Nguyen Huu Hien on 5/17/14.
//  Copyright (c) 2014 Nguyen Huu Hien. All rights reserved.
//

#import "OptionOperatorViewController.h"
#import "GameViewController.h"

@interface OptionOperatorViewController ()

@end

@implementation OptionOperatorViewController
@synthesize mathOperator;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    mathOperator = [[Operator alloc]init];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"game_segue"]) {
        [segue.destinationViewController setMathOperator:mathOperator];
    }
}

- (IBAction)unLimitTimeClick:(id)sender {
    UIImage *selectPlease ;
    if (!mathOperator.unLimitTime) {
        selectPlease = [UIImage imageNamed:@"select_please2chkd.png"];
        
    } else {
        selectPlease = [UIImage imageNamed:@"select_please2.png"];
    }
    [_imgSelectPlease setImage:selectPlease];
    mathOperator.unLimitTime = !mathOperator.unLimitTime;
}

- (IBAction)addAndSubtractClick:(id)sender {
    UIImage *bgImageButton;
    if (!mathOperator.add_minus) {
        bgImageButton = [UIImage imageNamed:@"addandsub.png"];
        
    } else {
        bgImageButton = [UIImage imageNamed:@"addandsubunch.png"];
    }
    mathOperator.add_minus = !mathOperator.add_minus;
    [_btnAddAndSubtract setImage:bgImageButton forState:UIControlStateNormal];
}

- (IBAction)multiplyAndDivideClick:(id)sender {
    UIImage *bgImageButton;
    if (!mathOperator.multiply_divied) {
        bgImageButton = [UIImage imageNamed:@"multanddev.png"];
        
    } else {
        bgImageButton = [UIImage imageNamed:@"multanddevunch.png"];
    }
    mathOperator.multiply_divied = !mathOperator.multiply_divied;
    [_btnMultiplyAndDivide setImage:bgImageButton forState:UIControlStateNormal];
}

- (IBAction)playClick:(id)sender {
    if (!mathOperator.add_minus && !mathOperator.multiply_divied && !mathOperator.greatest_smallest
        && !mathOperator.mixedOperation && !mathOperator.fractions) {
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:@"Please select a funtion" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [alert show];
    } else {
        [self performSegueWithIdentifier:@"game_segue" sender:self];
    }
    
}

- (IBAction)backClick:(id)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (IBAction)greatestAndSmallestClick:(id)sender {
    UIImage *bgImageButton;
    if (!mathOperator.greatest_smallest) {
        bgImageButton = [UIImage imageNamed:@"grtsml.png"];
        
    } else {
        bgImageButton = [UIImage imageNamed:@"grtsmlunch.png"];
    }
    mathOperator.greatest_smallest = !mathOperator.greatest_smallest;
    [_btnGreatestAndSmallest setImage:bgImageButton forState:UIControlStateNormal];
}

- (IBAction)mixedOperatorClick:(id)sender {
    UIImage *bgImageButton;
    if (!mathOperator.mixedOperation) {
        bgImageButton = [UIImage imageNamed:@"mixed.png"];
        
    } else {
        bgImageButton = [UIImage imageNamed:@"mixedunch.png"];
    }
    mathOperator.mixedOperation = !mathOperator.mixedOperation;
    [_btnMixedOperator setImage:bgImageButton forState:UIControlStateNormal];
}

- (IBAction)fractionsClicks:(id)sender {
    UIImage *bgImageButton;
    if (!mathOperator.fractions) {
        bgImageButton = [UIImage imageNamed:@"equals.png"];
        
    } else {
        bgImageButton = [UIImage imageNamed:@"equalsunch.png"];
    }
    mathOperator.fractions = !mathOperator.fractions;
    [_btnFractions setImage:bgImageButton forState:UIControlStateNormal];
}

@end
